﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ZhongKeSite.Common.Helper
{
    public class VerifyHelper
    {
        /// <summary>
        /// 手机号码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool IsPhone(string input)
        {
            Regex regex = new Regex(@"^1\d{10}$");
            return regex.IsMatch(input);
        }

        /// <summary>
        /// 密码策略
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool PwdStrategy(string input)
        {
            Regex regex = new Regex(@"^[\S]{6,20}$");
            return regex.IsMatch(input);
        }

        /// <summary>
        /// 纳税人识别号
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool CreditCodeStrategy(string input)
        {
            string[] regArray = new string[] { @"^[\da-z]{10,15}$", @"^\d{6}[\da-z]{10,12}$", @"^[a-z]\d{6}[\da-z]{9,11}$", @"^[a-z]{2}\d{6}[\da-z]{8,10}$", @"^\d{14}[\dx][\da-z]{4,5}$", @"^\d{17}[\dx][\da-z]{1,2}$", @"^[a-z]\d{14}[\dx][\da-z]{3,4}$", @"^[a-z]\d{17}[\dx][\da-z]{0,1}$", @"^[\d]{6}[\da-z]{13,14}$" };
            bool result = false;
            string reg = regArray.ToList().FirstOrDefault(x => new Regex(x, RegexOptions.IgnoreCase).IsMatch(input));
            result = !string.IsNullOrWhiteSpace(reg);
            return result;
        }

        /// <summary>
        /// 纳税人识别号
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool Email(string input)
        {
            Regex regex = new Regex(@"^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
            return regex.IsMatch(input);
        }

        
    }
}
